package com.hkd.forum.controller;

import com.hkd.forum.common.AppResult;
import com.hkd.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "TestController 测试接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1，显示spring 你好")
    @RequestMapping("/hello")
    public String hello(){
        return "hello this is Spring project";
    }

    @ApiOperation("测试接口4，显示你好+姓名")
    @RequestMapping("/helloName")
    public AppResult helloName(@ApiParam("姓名") @RequestParam("name") String name){
        return AppResult.success("hello :"+ name);
    }

    @ApiOperation("测试接口2，显示抛出异常信息")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception....");
    }
    @ApiOperation("测试接口3，显示自定义异常信息")
    @GetMapping("/appException")
    public AppResult textApplicationException(){
        throw new ApplicationException("这是一个ApplicationException。。。");
    }
}
